﻿Public Class Proveedores 

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub ProveedoresBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProveedoresBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.ProveedoresBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub Proveedores_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.proveedores' table. You can move, or remove it, as needed.
        Me.ProveedoresTableAdapter.Fill(Me.DbFireAndIceDataSet.proveedores)
        PanelArriba.Enabled = False
    End Sub

    Private Sub agregar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
        PanelArriba.Enabled = True
        Me.IdproveedorTextBox.ReadOnly = True
        Me.DescripcionTextBox.ReadOnly = False
        Me.DireccionTextBox.ReadOnly = False
        Me.Telefono1TextBox.ReadOnly = False
        Me.Telefono2TextBox.ReadOnly = False
        Me.CorreoelectronicoTextBox.ReadOnly = False
        Me.SitiowebTextBox.ReadOnly = False
        Me.ObservacionTextBox.ReadOnly = False
        Me.PersonacontactoTextBox.ReadOnly = False
    End Sub

    Private Sub modificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modificar.Click
        Mostrar()
        PanelArriba.Enabled = True
        Me.IdproveedorTextBox.ReadOnly = True
        Me.DescripcionTextBox.ReadOnly = False
        Me.DireccionTextBox.ReadOnly = False
        Me.Telefono1TextBox.ReadOnly = False
        Me.Telefono2TextBox.ReadOnly = False
        Me.CorreoelectronicoTextBox.ReadOnly = False
        Me.SitiowebTextBox.ReadOnly = False
        Me.ObservacionTextBox.ReadOnly = False
        Me.PersonacontactoTextBox.ReadOnly = False

    End Sub

    Private Sub eliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                ProveedoresTableAdapter.DeleteQuery(IdproveedorTextBox.Text)
                Me.ProveedoresTableAdapter.Fill(Me.DbFireAndIceDataSet.proveedores)

            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try


        End If
    End Sub

    Private Sub guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles guardar.Click
        If DescripcionTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar un nombre para el Documento")
        Else
            ErrorProvider1.SetError(DescripcionTextBox, Nothing)


            ProveedoresBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
            Me.IdproveedorTextBox.ReadOnly = True
            Me.DescripcionTextBox.ReadOnly = True
            Me.DireccionTextBox.ReadOnly = True
            Me.Telefono1TextBox.ReadOnly = True
            Me.Telefono2TextBox.ReadOnly = True
            Me.CorreoelectronicoTextBox.ReadOnly = True
            Me.SitiowebTextBox.ReadOnly = True
            Me.ObservacionTextBox.ReadOnly = True
            Me.PersonacontactoTextBox.ReadOnly = True

        End If
    End Sub

    Private Sub cancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        Mostrar()
        Me.ProveedoresTableAdapter.Fill(Me.DbFireAndIceDataSet.proveedores)
    End Sub

    Private Sub imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub
End Class